home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / progs / Netobj / CDK / NetObjectsFusionCDK5_97.exe / _SETUP.1 / TimeBasedComp.java < prev    next >
Encoding:
Java Source  |  1997-05-14  |  9.4 KB  |  308 lines

  1. import ComponentApp;
  2.  
  3. public class TimeBasedComp extends ComponentApp
  4. {
  5.     int maxWidth;
  6.     int maxHeight;
  7.     int numImages;
  8.     static final int MaxImages=24;
  9.     DDrawJava theJavaApplet; 
  10.     int[] imageNames;
  11.     int[] imageURLs;
  12.     int[] imageStarts;
  13.     DAssetManager assetMan;
  14.     
  15.     public void onCopy()
  16.     {
  17.         int[] imageNamesOld=imageNames;
  18.         int[] imageURLsOld=imageURLs;
  19.         imageNames=new int[MaxImages];
  20.         imageURLs=new int[MaxImages];
  21.         for(int cnt=0;cnt<numImages;cnt++)
  22.         {
  23.             imageNames[cnt]=imageNamesOld[cnt];
  24.             imageURLs[cnt]=imageURLsOld[cnt];
  25.             if(imageNames[cnt]!=0)
  26.                 assetMan.CopyAsset(imageNames[cnt]);
  27.             if(imageURLs[cnt]!=0)
  28.                 assetMan.CopyAsset(imageURLs[cnt]);
  29.         }
  30.     }
  31.     
  32.     
  33.     public String onInstall(DAssetManager cam, String codebase) 
  34.     { 
  35.         assetMan=cam;
  36.         return "Time Based Picture";
  37.     }
  38.     
  39.     public void onInspect(CStringArray Names,CStringArray Types)
  40.     {
  41.         Names.Set("Number of Images");
  42.         Types.Set(typeJavaCollection);
  43.         for(int cnt=0; cnt<numImages; cnt++)
  44.         {
  45.             Names.Set("Image "+Integer.toString(cnt+1));
  46.             Types.Set(typeImage);
  47.             Names.Set("URL for Image "+Integer.toString(cnt+1));
  48.             Types.Set(typeLink);
  49.             Names.Set("Start Time for Image "+Integer.toString(cnt+1));
  50.             Types.Set("Set(12am|1am|2am|3am|4am|5am|6am|7am|8am|9am|10am|11am|12pm|1pm|2pm|3pm|4pm|5pm|6pm|7pm|8pm|9pm|10pm|11pm)");
  51.         }
  52.         
  53.     }
  54.     
  55.     public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp) 
  56.     {
  57.         if (Get == 1)
  58.         {
  59.             if (Event.compareTo("Number of Images") == 0)
  60.             {
  61.                 return Integer.toString(numImages);
  62.             }
  63.             else
  64.             {
  65.                 for(int cnt=0; cnt<numImages; cnt++)                            
  66.                 {
  67.                     if (Event.compareTo("Image "+Integer.toString(cnt+1))==0)
  68.                         return Integer.toString(imageNames[cnt]);
  69.                     if (Event.compareTo("URL for Image "+Integer.toString(cnt+1))==0)
  70.                         return Integer.toString(imageURLs[cnt]);
  71.                     if (Event.compareTo("Start Time for Image "+Integer.toString(cnt+1))==0)
  72.                         return Integer.toString(imageStarts[cnt]);
  73.                 }
  74.             }
  75.         }
  76.         else
  77.         {
  78.             if (Event.compareTo("Number of Images") == 0)
  79.             {
  80.                 int newNumImages=Integer.parseInt(Value,10);
  81.                 if(newNumImages>MaxImages)
  82.                     newNumImages=MaxImages;
  83.                 if(newNumImages<numImages)
  84.                 {
  85.                     DImage imageSizer=new DImage();
  86.                     maxHeight=maxWidth=0;
  87.                     for(int iter=0;iter<newNumImages;iter++)
  88.                     {
  89.                         String theImageFile=assetMan.GetAssetLocation(imageNames[iter], IAssetContext.Preview, IFileNameStyle.DosName);
  90.                         imageSizer.setImageFile(theImageFile);
  91.                         IDSize currentImageSize=imageSizer.getSize();
  92.                         if(currentImageSize.getHeight()>maxHeight)
  93.                         {
  94.                             maxHeight=currentImageSize.getHeight();
  95.                         }
  96.                         if(currentImageSize.getWidth()>maxWidth)
  97.                         {
  98.                             maxWidth=currentImageSize.getWidth();
  99.                         }
  100.                     }
  101.                     theJavaApplet.SetSize(maxWidth, maxHeight);
  102.                 }
  103.                 while(newNumImages<numImages)
  104.                 {
  105.                     assetMan.RemoveAsset(imageNames[--numImages]);
  106.                 }
  107.                 numImages=newNumImages;
  108.                 theJavaApplet.AddParam(Event,typeString,Value);                                
  109.             }
  110.             else 
  111.             {
  112.                 for(int cnt=0; cnt<numImages; cnt++)
  113.                 {
  114.                     if (Event.compareTo("Image "+Integer.toString(cnt+1))==0)
  115.                     {    
  116.                         if(imageNames[cnt]!=0)
  117.                         {
  118.                             assetMan.RemoveAsset(imageNames[cnt]);
  119.                         }
  120.                         imageNames[cnt]=Integer.parseInt(Value,10);
  121.                         String theImageFile=assetMan.GetAssetLocation(imageNames[cnt], IAssetContext.Preview, IFileNameStyle.DosName);
  122.                         theJavaApplet.setImageFile(theImageFile);
  123.                         DImage imageSizer=new DImage();
  124.                         maxHeight=maxWidth=0;
  125.                         for(int iter=0;iter<numImages;iter++)
  126.                         {
  127.                             theImageFile=assetMan.GetAssetLocation(imageNames[iter], IAssetContext.Preview, IFileNameStyle.DosName);
  128.                             imageSizer.setImageFile(theImageFile);
  129.                             IDSize currentImageSize=imageSizer.getSize();
  130.                             if(currentImageSize.getHeight()>maxHeight)
  131.                             {
  132.                                 maxHeight=currentImageSize.getHeight();
  133.                             }
  134.                             if(currentImageSize.getWidth()>maxWidth)
  135.                             {
  136.                                 maxWidth=currentImageSize.getWidth();
  137.                             }
  138.                         }
  139.                         theJavaApplet.SetSize(maxWidth, maxHeight);
  140.                     }
  141.                     if (Event.compareTo("URL for Image "+Integer.toString(cnt+1))==0)
  142.                         imageURLs[cnt]=Integer.parseInt(Value,10);
  143.                     if (Event.compareTo("Start Time for Image "+Integer.toString(cnt+1))==0)
  144.                     {
  145.                         if(cnt!=0)
  146.                         {
  147.                             imageStarts[cnt]=Integer.parseInt(Value,10);
  148.                             if(imageStarts[cnt]>23)
  149.                                 imageStarts[cnt]=23;
  150.                             else if(imageStarts[cnt]<0)
  151.                                 imageStarts[cnt]=0;
  152.                         }
  153.                     }
  154.                 }
  155.             }    
  156.             
  157.             
  158.         }
  159.         return "";
  160.     }
  161.     
  162.     
  163.     public void onDrop(IDLayout layout, IDRect r, int fDrop) 
  164.     {
  165.         if (fDrop != ActivateState.Drop)  // the first time the component is dropped
  166.             return;
  167.         
  168.         maxWidth=0;
  169.         maxHeight=0;
  170.  
  171.         int xPos;
  172.         int yPos;
  173.  
  174.         numImages=3;
  175.         imageURLs=new int[24];
  176.         imageNames=new int[24];
  177.         imageStarts=new int[24];
  178.         for(int i=0;i<24;i++)
  179.         {
  180.             imageNames[i]=0;
  181.             imageURLs[i]=0;
  182.             imageStarts[i]=i;
  183.         }
  184.         theJavaApplet = new DDrawJava();
  185.         theJavaApplet.setImageFile(theJavaApplet.getCodeBase() + "banner.gif");
  186.         theJavaApplet.setAppletFileName(theJavaApplet.getCodeBase() + "TimeBased.class");                
  187.         theJavaApplet.setStretch(PictureStretchMode.DRAW_NATURAL);
  188.         theJavaApplet.setAltTag("Time Based Loader");
  189.         xPos=r.getLeft();
  190.         yPos=r.getTop();
  191.         layout.AddObject(theJavaApplet);
  192.         theJavaApplet.AddParam("Number of Images",typeString,"3");                                
  193.         imageNames[0] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner.gif",IAssetType.Image,"");    
  194.         imageNames[1] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner2.gif",IAssetType.Image,"");    
  195.         imageNames[2] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner3.gif",IAssetType.Image,"");    
  196.         DImage imageSizer=new DImage();
  197.         imageSizer.setImageFile(theJavaApplet.getCodeBase() + "banner.gif");
  198.         IDSize currentImageSize=imageSizer.getSize();
  199.         if(currentImageSize.getHeight()>maxHeight)
  200.         {
  201.             maxHeight=currentImageSize.getHeight();
  202.             if(currentImageSize.getWidth()>maxWidth)
  203.                 maxWidth=currentImageSize.getWidth();
  204.             theJavaApplet.SetPositionRect(xPos, yPos, xPos+maxWidth, yPos+maxHeight);
  205.         }
  206.         else if(currentImageSize.getWidth()>maxWidth)
  207.         {
  208.             maxWidth=currentImageSize.getWidth();
  209.             theJavaApplet.SetPositionRect(xPos, yPos, xPos+maxWidth, yPos+maxHeight);
  210.         }
  211.     }
  212.     
  213.     public void onUnInstall(DAssetManager cam) 
  214.     {
  215.         
  216.     }
  217.     
  218.     protected void finalize() 
  219.     {
  220.         for(int cnt=0;cnt<numImages;cnt++)
  221.         {
  222.             if(imageNames[cnt]!=0)
  223.                 assetMan.RemoveAsset(imageNames[cnt]);
  224.         }
  225.     }
  226.     
  227.     public void onPublish(DAssetManager asm, int context)
  228.     {
  229.         
  230.         if(context==IAssetContext.Preview)
  231.         {
  232.             for(int cnt=0;cnt<numImages;cnt++)
  233.             {
  234.                 String theLoc=assetMan.GetAssetLocation(imageNames[cnt],context, IFileNameStyle.HTMLName);
  235.                 theLoc.replace('|',':');
  236.                 theJavaApplet.AddParam("Image "+Integer.toString(cnt+1),typeString,"file:///"+theLoc);
  237.             }
  238.         }
  239.         else
  240.         {
  241.             for(int cnt=0;cnt<numImages;cnt++)
  242.             {
  243.                 theJavaApplet.AddParam("Image "+Integer.toString(cnt+1),typeString,assetMan.GetAssetRelativeLocation(imageNames[cnt],context, 0));                                
  244.             }
  245.         }
  246.         for(int cnt=0;cnt<numImages;cnt++)
  247.         {
  248.             String theURL;
  249.             if(imageURLs[cnt]!=0)
  250.             {
  251.                 theURL=assetMan.GetAssetLocation(imageURLs[cnt], context, IFileNameStyle.DosName);
  252.             }
  253.             else
  254.             {
  255.                 theURL="";
  256.             }
  257.             theJavaApplet.AddParam("URL for Image "+Integer.toString(cnt+1),typeString,theURL);                                
  258.             theJavaApplet.AddParam("Start Time for Image "+Integer.toString(cnt+1),typeString,Integer.toString(imageStarts[cnt]));
  259.         }
  260.         theJavaApplet.AddParam("Image Width",typeString,Integer.toString(maxWidth));
  261.         theJavaApplet.AddParam("Image Height",typeString,Integer.toString(maxHeight));
  262.  
  263.         IDRect thePosition=theJavaApplet.getObjectRect();
  264.         theJavaApplet.AddParam("X Position",typeString,Integer.toString(thePosition.getLeft()));
  265.         theJavaApplet.AddParam("Y Position",typeString,Integer.toString(thePosition.getTop()+7));
  266.  
  267.         IDLayout layout = theJavaApplet.getLayout();
  268.         IDSite site  = layout.getSite();
  269.         IDStyle style = site.getCurrentStyle();        
  270.         
  271.  
  272.         int backgroundStyle = layout.getBackgroundStyle();
  273.         
  274.         if (backgroundStyle != BackgroundStyle.None)
  275.         {
  276.             if (backgroundStyle == BackgroundStyle.SolidColor)
  277.                 theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(layout.getBackgroundColor()));
  278.             else if (backgroundStyle == BackgroundStyle.Image)
  279.             {
  280.                 int backID = assetMan.AddAsset(layout.getBackgroundImage(),IAssetType.Image,"");        
  281.                 String theParam=assetMan.GetAssetRelativeLocation(backID,context,1);
  282.                 if(context == IAssetContext.Preview)
  283.                     theParam="file:///"+theParam;
  284.                 theJavaApplet.AddParam("BackgroundImage",typeString,theParam);
  285.             }
  286.         }
  287.         else
  288.         {        
  289.             backgroundStyle = style.getBackgroundStyle();
  290.             
  291.             if (backgroundStyle == BackgroundStyle.SolidColor)
  292.                 theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(style.getBackgroundColor()));
  293.             else if (backgroundStyle == BackgroundStyle.Image)
  294.             {
  295.                 int backID = assetMan.AddAsset(style.getBackgroundImage(),IAssetType.Image,"");        
  296.                 String theParam=assetMan.GetAssetRelativeLocation(backID,context,1);
  297.                 if(context == IAssetContext.Preview)
  298.                     theParam="file:///"+theParam;
  299.                 theJavaApplet.AddParam("BackgroundImage",typeString,theParam);
  300.             }
  301.         }
  302.  
  303.     }
  304.     
  305.     
  306.     
  307.     
  308. }